﻿using CNKI.TPI.Web.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CNKI.TPI.Web.UI.Controllers.Search
{
    public class SmartWordController : Controller
    {
        //
        // GET: /SmartWord/

        public string Index(string tag, string key)
        {
            string content = "";
            try
            {
                if (ConfigHelper.IsSmartwordEnabled())
                {
                    content = BaseHttpClient.CallInterfaceGet(ConfigHelper.GetSmartwordAddress(), "tag=" + tag + "&param=" + key);
                    content = content.TrimStart('"').TrimEnd('"');
                }

                //if (content != null && content.Length > 0)
                //{
                //    content = content.Substring(1, content.Length - 2);
                //    if (content.Contains(";"))
                //    {
                //        int count = int.Parse(length);
                //        string[] wordList = content.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                //        if (wordList.Count() > count)
                //        {
                //            content = wordList[0];
                //            for (int i = 1; i < count; i++)
                //            {
                //                content = content + ";" + wordList[i];
                //            }
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return content;
        }
    }
}
